package org.ocelot.tunes4j.dbexample;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.ocelot.tunes4j.beans.PlayList;
import org.ocelot.tunes4j.dao.IbatisSQLSessionUtil;
import org.ocelot.tunes4j.dao.PlayListDAO;

public class IbatisExample {

	public static void main(String[] args) {
//		getPlayList();
		insertPlaylist();
	}
	
	public static void getPlayList() {
		SqlSessionFactory factory = IbatisSQLSessionUtil.getSQLSessionFactory();
		SqlSession session = factory.openSession();
		try {
			//PlayList playlist = (PlayList) session.selectOne("dao.PlayListMapper.findByName","Test1");
			PlayListDAO mapper = session.getMapper(PlayListDAO.class);
			PlayList playlist = mapper.findByName("Test1");
			System.out.println(playlist);
		} finally {
			session.close();
		}
	}
	
	public static void insertPlaylist() {
		SqlSessionFactory factory = IbatisSQLSessionUtil.getSQLSessionFactory();
		SqlSession session = factory.openSession();
		try {
			PlayListDAO mapper = session.getMapper(PlayListDAO.class);
			PlayList play = new PlayList();
			play.setId(1212);
			play.setName(null);
			mapper.insert(play);
			System.out.println(play);
		} finally {
			session.close();
		}
	}
	
}
